//
//  ViewController.m
//  QizAIDemo
//
//  Created by Mephisto on 2025/4/22.
//

#import "ViewController.h"
#import "ToolView.h"
#import <FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.h>
#import <Masonry/Masonry.h>
#import <QMUIKit/QMUIKit.h>

// 引入 QizAIFramework 头文件
#import <QizAIFramework/QizAIFramework-Swift.h>

@interface ViewController () <QizAIControllerDelegate>
@property(nonatomic, strong) ToolView *toolView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
    self.fd_interactivePopDisabled = YES;

    self.view.backgroundColor = [UIColor qmui_colorWithHexString:@"#F9F9F9"];
    [self.view addSubview:self.toolView];

    [self setupLayout];
    [self bindViewModel];
}

- (void)bindViewModel {
    [self.toolView.sureBtn addTarget:self
                              action:@selector(btnClick:)
                    forControlEvents:UIControlEventTouchUpInside];
}

- (void)btnClick:(UIButton *)btn {
    [self.view endEditing:true];
    if (self.toolView.memeberIdTF.text.length == 0) {
        [QMUITips showWithText:@"请输入MemberId"];
        return;
    }

    NSString *memeberId = self.toolView.memeberIdTF.text;
    NSString *accountNo = self.toolView.accountNoTF.text;
    
    //scheme：hkcgis：正式环境、hkcgisuat：UAT环境
    QizAIController *controller =
        [[QizAIController alloc] initWithMemberId:memeberId
                                        accountNo:accountNo
                                           scheme:@"hkcgisuat"];
    controller.delegate = self;
    [self.navigationController pushViewController:controller animated:true];
}

#pragma mark -  QizAIController 代理

- (void)jumpControllerWithUrl:(NSURL *)url {
    [[UIApplication sharedApplication] openURL:url
                                       options:@{}
                             completionHandler:nil];
}

#pragma mark - 界面布局

- (void)setupLayout {

    [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.leading.trailing.equalTo(self.view);
      make.top.equalTo(self.view).offset(160);
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:true];
}

#pragma mark -  懒加载

- (ToolView *)toolView {
    if (_toolView == nil) {
        _toolView = ToolView.new;
    }
    return _toolView;
}

@end
